/*
 * @lc app=leetcode.cn id=1154 lang=cpp
 *
 * [1154] 一年中的第几天
 */

// @lc code=start
class Solution
{
public:
    int dayOfYear(string date)
    {
        //一年的第几天
        //一次读取date
        int year = atoi(date.substr(0, 4).c_str());
        int month = atoi(date.substr(5, 2).c_str());
        int day = atoi(date.substr(8, 2).c_str());
        int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        bool istrue = false; //是否为闰年
        if (year % 4 == 0 || year % 400 == 0)
        {
            istrue = true;
        }
        int res = 0;
        for (int i = 0; i < month - 1; i++)
        {
            if (i == 1 && istrue)
            {
                res++;
            }
            res += months[i];
        }
        return res + day;
    }
};
// @lc code=end
